package com.vote.www.service;

import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vote.www.domain.Czjvote;
import com.vote.www.domain.Czjvotenum;
import com.vote.www.domain.Czjweixinvote;
import com.vote.www.persistence.CzjvoteMapper;
import com.vote.www.utils.UUIDUtils;

@Service("czjvoteService")
public class CzjvoteService {
	@Autowired
	private CzjvoteMapper czjvoteMapper;
	
	/**
	 * 新增czj_weixinvote  微信投票信息
	 * @param czjweixinvote
	 * @param param
	 */
	@Transactional
	public void insertCzjweixinvote(Czjweixinvote czjweixinvote) {
		czjweixinvote.setWeixinvoteId(UUIDUtils.getUUID());
		czjvoteMapper.insertCzjweixinvote(czjweixinvote);
	}

	/**
	 * 查询某个czj_vote 投票表
	 * @param param
	 * @return
	 */
	public Czjvote getCzjvote(Map<String,Object> param) {
		return czjvoteMapper.getCzjvote(param);
	}
	
	
	/**
	 * 查询某个czj_vote 投票表
	 * @param param
	 * @return
	 */
	public Czjvotenum getCzjvoteNum(Map<String,Object> param) {
		return czjvoteMapper.getCzjvoteNum(param);
	}	
   
	/**
	 * 查询某个czj_vote 投票表(最新)
	 * @param param
	 * @return
	 */
	public Czjvote getPidNew(Map<String,Object> param) {
		return czjvoteMapper.getPidNew(param);
	}	
		
	/**
	 * 查询czj_vote 投票表列表
	 * @return
	 */
	public Map<String,Object> getCzjvoteList(Map<String,Object> param) {
		Map<String,Object> returnMap = new HashMap<String,Object>();
		returnMap.put("totalCounts", czjvoteMapper.getTotalRows(param));
		returnMap.put("list", czjvoteMapper.getCzjvoteList(param));
		return returnMap;
	}
   
/*	*//**
	 * 查询czj_vote 投票表列表
	 * @return
	 *//*
	public  Pagination getCzjvoteList(Map<String,Object> param,int pageSize,Integer pageNo,String order,String sort) {
		Pagination p = new Pagination();
		p.setPageNo(pageNo);
		p.setPageSize(pageSize);
		p.setOrder(order);
		p.setSort(sort);
		param.putAll(p.toMap());
		int count=czjvoteMapper.getTotalRows(param);
		List<Czjvote> list=	czjvoteMapper.getCzjvoteList(param);
	
		p.setList(list);
		p.setTotalCount(count);
		return p;
		
	}*/
      
	/**
	 * 新增czj_vote 投票表
	 * @param czjvote
	 * @param param
	 */
	@Transactional
	public void insertCzjvote(Czjvote czjvote) {
		czjvote.setVoteId(UUIDUtils.getUUID());
		czjvoteMapper.insertCzjvote(czjvote);
	}
	
	/**
	 * 新增czj_votenum 投票表
	 * @param czjvotenum
	 * @param param
	 */
	@Transactional
	public void insertCzjvotenum(Czjvotenum czjvotenum) {
		czjvoteMapper.insertCzjvotenum(czjvotenum);
	}	
	/**
	 * 新增czj_vote 投票表(后台)
	 * @param czjvote
	 * @param param
	 */
	@Transactional
	public void insertCzjvoteBack(Map<String,Object> param) {
		czjvoteMapper.insertCzjvoteBack(param);
	}	
   
	/**
	 * 编辑czj_vote 投票表
	 * @param czjvote
	 * @param param
	 */
	@Transactional
	public void updateCzjvote(Czjvote czjvote) {
		czjvoteMapper.updateCzjvote(czjvote);
	}
   
	/**
	 * 编辑czj_vote 投票表
	 * @param czjvote
	 * @param param
	 */
	@Transactional
	public void updateCzjvotenum(Czjvotenum czjvotenum) {
		czjvoteMapper.updateCzjvotenum(czjvotenum);
	}
	
	
	/**
	 * 删除czj_vote 投票表
	 * @param param
	 */    
	@Transactional
	public void deleteCzjvote(List<String> voteIdList) {
		for(String voteId: voteIdList){
	  		Map<String,Object> param = new HashMap<String,Object>();
	  		param.put("voteId", voteId);
	 	   czjvoteMapper.deleteCzjvote(param);	  		
		}
	}
	
	/**
	 * 删除czj_vote 投票表数量
	 * @param param
	 */    
	@Transactional
	public void deleteCzjvotenumtrue(Map<String,Object> param) {
	 	   czjvoteMapper.deleteCzjvotenumtrue(param);	  		
		
	}	
	
		
	
	
	/**
	 * 删除czj_vote 投票表(后台)
	 * @param param
	 */    
	@Transactional
	public void deleteCzjvoteBack(Map<String,Object> param) {
	 	   czjvoteMapper.deleteCzjvoteBack(param);	  		
		
	}

	/**
	 * 删除czj_vote 投票表NUM
	 * @param param
	 */    
	@Transactional
	public void deleteCzjvotenum() {
	 	   czjvoteMapper.deleteCzjvotenum();	  				
	}	
		
	
	/**
	 * 获取有投票数的用户id
	 * @param param
	 */    
	@Transactional
	public List<String> CzjvoteUserInfoId(){
	 	   return czjvoteMapper.CzjvoteUserInfoId();	  				
	}	
	
	/**
	 * 获取有投票数的用户id
	 * @param param
	 */    
	@Transactional
	public void insertUserInfoIdAndVotenum(Map<String,Object> map){
	 	   czjvoteMapper.insertUserInfoIdAndVotenum(map);	  				
	}
	

}